package com.bargate.domain.spring.expression.configuration;

import com.bargate.domain.spring.expression.value.*;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;

import java.util.Calendar;
import java.util.Date;


/**
 * Created by IntelliJ IDEA.
 * User: EAD-MASTER
 * Date: 18/09/2010
 * Time: 21:55:07
 * To change this template use File | Settings | File Templates.
 */
@Configuration
@Import(ConfigurationGeneralBeans.class)
public class ConfigurationForPropertyAccess implements BeanFactoryAware {
    private BeanFactory beanFactory;

    @Bean
    BeanPropertyGetSetOperations InjectViaValueAnnotation() {
        BeanPropertyGetSetOperations getSetOperations = new BeanPropertyGetSetOperations();
        getSetOperations.setBeanFactory(beanFactory);
        return getSetOperations;
    }

    @Bean
    ArithmeticOperations ArithmeticOperations() {
        return new ArithmeticOperations();
    }

    @Bean
    RelationalOperations RelationalOperations() {
        return new RelationalOperations();
    }


    @Bean
    LogicalOperations LogicalOperations() {
        return new LogicalOperations();
    }

    @Bean
    TernaryElvisAndSafeNavigationOperations TernaryAndElvisOperations() {
        return new TernaryElvisAndSafeNavigationOperations();
    }

    @Bean
    CollectionSelectionOperations CollectionSelectionOperations() {
        return new CollectionSelectionOperations();
    }

    @Bean
    MapSelectionOperations MapSelectionOperations() {
        return new MapSelectionOperations();
    }

    @Bean
    CollectionProjectionOperations CollectionProjectionOperations() {
        return new CollectionProjectionOperations();
    }


    @Bean
    SystemEnvPropsDateParseOperations SystemEnvPropsDateParseOperations() {
        Calendar calendar = Calendar.getInstance();
        calendar.set(2010, 11, 25, 0, 0, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        Expression expression = new SpelExpressionParser().parseExpression("'2010/12/25'");
        Date value = expression.getValue(Date.class);


        return new SystemEnvPropsDateParseOperations();
    }


    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }
}
